e18239e259627457278f9e893e561d85e61365ed,impl/src/java/org/sakaiproject/evaluation/logic/EvalEmailsLogicImpl.java,EvalEmailsLogicImpl,sendEvalAvailableNotifications,#number#boolean#,173
Before Change
List<EvalAssignGroup> assignGroups = evalAssignGroups.get(evaluationId);
List<String> sentEmails = new ArrayList<String>();
int emailsSentCt=0;
// loop through groups and send emails to correct users group
for (int i = 0; i < assignGroups.size(); i++) {
EvalAssignGroup assignGroup = assignGroups.get(i);
if(! commonLogic.isEvalGroupPublished(assignGroup.getEvalGroupId())) {
log.info("Skipping available email for evaluationId ("+evaluationId+") and group ("+assignGroup.getEvalGroupId()+") because the group is not published");
continue;
}
EvalGroup group = commonLogic.makeEvalGroupObject(assignGroup.getEvalGroupId());
if (eval.getInstructorOpt().equals(EvalConstants.INSTRUCTOR_REQUIRED)) {
// notify eval takers
List<EvalAssignUser> userAssignments = evaluationService.getParticipantsForEval(evaluationId, null,
new String[] {group.evalGroupId}, EvalAssignUser.TYPE_EVALUATOR, null, null, null);
userIdsSet = EvalUtils.getUserIdsFromUserAssignments(userAssignments);
studentNotification = true;
} else {
//instructor may opt-in or opt-out
if (assignGroup.getInstructorApproval().booleanValue()) {
// instructor has opted-in, notify students
List<EvalAssignUser> userAssignments = evaluationService.getParticipantsForEval(evaluationId, null,
new String[] {group.evalGroupId}, EvalAssignUser.TYPE_EVALUATOR, null, null, null);
userIdsSet = EvalUtils.getUserIdsFromUserAssignments(userAssignments);
studentNotification = true;
} else {
if (eval.getInstructorOpt().equals(EvalConstants.INSTRUCTOR_OPT_IN) && includeEvaluatees) {
// instructor has not opted-in, notify instructors
List<EvalAssignUser> userAssignments = evaluationService.getParticipantsForEval(evaluationId, null,
new String[] {group.evalGroupId}, EvalAssignUser.TYPE_EVALUATEE, null, null, null);
userIdsSet = EvalUtils.getUserIdsFromUserAssignments(userAssignments);
studentNotification = false;
} else {
userIdsSet = new HashSet<String>();
}
}
}
// skip ahead if there is no one to send to
if (userIdsSet.size() == 0) {
log.info("Skipping available email for evaluationId ("+evaluationId+") and group ("+assignGroup.getEvalGroupId()+") because there is no one (instructors or participants) to send the email to");
continue;
}
// turn the set into an array
String[] toUserIds = (String[]) userIdsSet.toArray(new String[] {});
if (log.isDebugEnabled()) {
log.debug("Found " + toUserIds.length + " users (" + ArrayUtils.arrayToString(toUserIds) + ") to send "
+ EvalConstants.EMAIL_TEMPLATE_CREATED + " notification to for available evaluation ("
+ evaluationId + ") and group (" + group.evalGroupId + ")");
}
// choose from 2 templates
EvalEmailTemplate currentTemplate = emailTemplate;
if (! studentNotification) {
currentTemplate = emailOptInTemplate;
}
EvalEmailMessage em = makeEmailMessage(currentTemplate.getMessage(), currentTemplate.getSubject(), eval, group);
// send the actual emails for this evalGroupId
String[] emailAddresses = sendUsersEmails(from, toUserIds, em.subject, em.message);
log.info("Sent evaluation available message to " + emailAddresses.length + " users (attempted to send to "+toUserIds.length+")");
emailsSentCt++;
// store sent emails to return
for (int j = 0; j < emailAddresses.length; j++) {
sentEmails.add(emailAddresses[j]);
}
commonLogic.registerEntityEvent(EVENT_EMAIL_AVAILABLE, eval);
}
// send email to admin that reminders are finished.
boolean sendJobCompletion = (Boolean) settings.get(EvalSettings.ENABLE_JOB_COMPLETION_EMAIL);
if (sendJobCompletion) {
Map<String, String> replacementValues = new HashMap<String, String>();
replacementValues.put("HelpdeskEmail", from);
replacementValues.put("EvalTitle", eval.getTitle());
Integer iEmailsSentCt = Integer.valueOf(emailsSentCt);
replacementValues.put("NumEmailsSent", iEmailsSentCt.toString());
replacementValues.put("JobType", EvalConstants.JOB_TYPE_ACTIVE.substring(9));
sendEmailJobCompleted(eval.getId(), replacementValues);
}
return (String[]) sentEmails.toArray(new String[] {});
}
After Change
boolean studentNotification = true;
EvalEvaluation eval = getEvaluationOrFail(evaluationId);
String from = getFromEmailOrFail(eval);
EvalEmailTemplate emailTemplate = getEmailTemplateOrFail(EvalConstants.EMAIL_TEMPLATE_AVAILABLE, evaluationId);
// get the instructor opt-in email template
EvalEmailTemplate emailOptInTemplate = getEmailTemplateOrFail(EvalConstants.EMAIL_TEMPLATE_AVAILABLE_OPT_IN, null);
// get the associated assign groups for this evaluation
Map<Long, List<EvalAssignGroup>> evalAssignGroups =
evaluationService.getAssignGroupsForEvals(new Long[] { evaluationId }, true, null);
List<EvalAssignGroup> assignGroups = evalAssignGroups.get(evaluationId);
List<String> sentEmails = new ArrayList<String>();
// loop through groups and send emails to correct users group
for (int i = 0; i < assignGroups.size(); i++) {
EvalAssignGroup assignGroup = assignGroups.get(i);
if(! commonLogic.isEvalGroupPublished(assignGroup.getEvalGroupId())) {
log.info("Skipping available email for evaluationId ("+evaluationId+") and group ("+assignGroup.getEvalGroupId()+") because the group is not published");
continue;
}
EvalGroup group = commonLogic.makeEvalGroupObject(assignGroup.getEvalGroupId());
if (eval.getInstructorOpt().equals(EvalConstants.INSTRUCTOR_REQUIRED)) {
// notify eval takers
List<EvalAssignUser> userAssignments = evaluationService.getParticipantsForEval(evaluationId, null,
new String[] {group.evalGroupId}, EvalAssignUser.TYPE_EVALUATOR, null, null, null);
userIdsSet = EvalUtils.getUserIdsFromUserAssignments(userAssignments);
studentNotification = true;
} else {
//instructor may opt-in or opt-out
if (assignGroup.getInstructorApproval().booleanValue()) {
// instructor has opted-in, notify students
List<EvalAssignUser> userAssignments = evaluationService.getParticipantsForEval(evaluationId, null,
new String[] {group.evalGroupId}, EvalAssignUser.TYPE_EVALUATOR, null, null, null);
userIdsSet = EvalUtils.getUserIdsFromUserAssignments(userAssignments);
studentNotification = true;
} else {
if (eval.getInstructorOpt().equals(EvalConstants.INSTRUCTOR_OPT_IN) && includeEvaluatees) {
// instructor has not opted-in, notify instructors
List<EvalAssignUser> userAssignments = evaluationService.getParticipantsForEval(evaluationId, null,
new String[] {group.evalGroupId}, EvalAssignUser.TYPE_EVALUATEE, null, null, null);
userIdsSet = EvalUtils.getUserIdsFromUserAssignments(userAssignments);
studentNotification = false;
} else {
userIdsSet = new HashSet<String>();
}
}
}
// skip ahead if there is no one to send to
if (userIdsSet.size() == 0) {
log.info("Skipping available email for evaluationId ("+evaluationId+") and group ("+assignGroup.getEvalGroupId()+") because there is no one (instructors or participants) to send the email to");
continue;
}
// turn the set into an array
String[] toUserIds = (String[]) userIdsSet.toArray(new String[] {});
if (log.isDebugEnabled()) {
log.debug("Found " + toUserIds.length + " users (" + ArrayUtils.arrayToString(toUserIds) + ") to send "
+ EvalConstants.EMAIL_TEMPLATE_CREATED + " notification to for available evaluation ("
+ evaluationId + ") and group (" + group.evalGroupId + ")");
}
// choose from 2 templates
EvalEmailTemplate currentTemplate = emailTemplate;
if (! studentNotification) {
currentTemplate = emailOptInTemplate;
}
EvalEmailMessage em = makeEmailMessage(currentTemplate.getMessage(), currentTemplate.getSubject(), eval, group);
// send the actual emails for this evalGroupId
String[] emailAddresses = sendUsersEmails(from, toUserIds, em.subject, em.message);
log.info("Sent evaluation available message to " + emailAddresses.length + " users (attempted to send to "+toUserIds.length+")");
// store sent emails to return
for (int j = 0; j < emailAddresses.length; j++) {
sentEmails.add(emailAddresses[j]);
}
commonLogic.registerEntityEvent(EVENT_EMAIL_AVAILABLE, eval);
}
String[] emailsSent = sentEmails.toArray(new String[sentEmails.size()]);
handleJobCompletion(eval, emailsSent, EvalConstants.JOB_TYPE_ACTIVE, from);
return emailsSent;
}